package top.tangyh.lamp.care.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import top.tangyh.basic.base.service.SuperService;
import top.tangyh.lamp.care.entity.BObsvCfgDetail;
import top.tangyh.lamp.care.vo.result.ObsvCfgDetailDto;
import top.tangyh.lamp.care.vo.save.BObsvCfgDetailSaveVO;
import top.tangyh.lamp.care.vo.update.BObsvCfgDetailUpdateVO;
import top.tangyh.lamp.care.vo.result.BObsvCfgDetailResultVO;
import top.tangyh.lamp.care.vo.query.BObsvCfgDetailPageQuery;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * <p>
 * 业务接口
 * 观察项配置明细表
 * </p>
 *
 * @author zqb
 * @date 2024-07-26 10:31:53
 * @create [2024-07-26 10:31:53] [zqb] [代码生成器生成]
 */
public interface BObsvCfgDetailService extends SuperService<Long, BObsvCfgDetail> {

    /**
     * 按观察项id找配置明细
     *
     * @param id  观察项id
     * @return
     */
    List<ObsvCfgDetailDto> selectByCfgId(Long id);


    /**
     * 根据观察项主表的id获得所有含有该主表项的结构体的明细
     *
     * @param obsvCfgId 观察项主表id
     * @return
     */
    List<BObsvCfgDetail> findByObsvCfgId(Long obsvCfgId);

    /**
     * 根据观察项主表的id,找出其所有子项,返回map,
     *
     * @param pid 观察项主表id,也是父id
     * @return key: 子项的系统id, 值为子项
     */
    default Map<Long, BObsvCfgDetail> findChilrdernWithMap(Long pid) {
        List<BObsvCfgDetail> list = findChilrdern(pid);
        Map<Long, BObsvCfgDetail> rst = list.stream().collect(Collectors.toMap(BObsvCfgDetail::getId, e -> e, (m1, m2) -> m1));
        return rst;
    }

    /**
     * 根据观察项主表的id,找出其所有子项
     *
     * @param pid 观察项主表id,也是父id
     * @return
     */
    default List<BObsvCfgDetail> findChilrdern(Long pid) {
        LambdaQueryWrapper<BObsvCfgDetail> queryWrapper = new LambdaQueryWrapper();
        queryWrapper.eq(BObsvCfgDetail::getObsvCfgId, pid);
        return getSuperManager().list(queryWrapper);
    }

    /**
     * 根据观察项主表的id,删除该项下的有子项
     *
     * @param pid 观察项主表id,也是父id
     * @return
     */
    default boolean delChildren(Long pid) {
        LambdaQueryWrapper<BObsvCfgDetail> queryWrapper = new LambdaQueryWrapper();
        queryWrapper.eq(BObsvCfgDetail::getObsvCfgId, pid);
        return getSuperManager().remove(queryWrapper);
    }
}


